<template>
	<yd-layout id='index'>
		<!--slot='top'-->
		<div class="search" >
			<div class="search_title">
				<img class="search_title_img" src="../../assets/index_1.png" alt="" />
			</div>
			
			<div class="search_s" >
				<img src="../../assets/search.png" alt="" />
				<div @click="goSearch" class="input_btn">搜索你想要的~</div>
				<!--<input type="text" placeholder="搜索你想要的~" />-->
			</div>
			<div v-if="true" class="search_msg" @click="$router.push({name:'message'})">
				<div v-if="unreadTotal>0" class="span"></div>
				<img class="search_img" src="../../assets/massage.png" alt="" />
			</div>
		</div>
		<div class="search_kong"></div>
		<div class="header">
			<div class="header_c">
				<van-swipe :autoplay="3000" indicator-color="white">
					<van-swipe-item v-for='item in bannerList'>
						<!--<a :href="item.web_url?item.web_url:'javascript:;'">-->
							<img  @click="goBannerView(item)" :src="item.img" alt="" />
						<!--</a>-->
					</van-swipe-item>
				</van-swipe>
			</div>
		</div>
		<div class="nav">
			<div class="list" @click="goNextPage('articleCompany',1)">
				<img src="../../assets/company.png" alt="" />
				<div>聚焦公司</div>
			</div>
			<div class="list" @click="goNextPage('productPresentation',2)">
				<img src="../../assets/product.png" alt="" />
				<div>产品展厅</div>
			</div>
			<div class="list" @click="goNextPage('teamLeader',3)">
				<img src="../../assets/book.png" alt="" />
				<div>领袖风采</div>
			</div>
			<div class="list" @click="goNextPage('storeSystem',4)">
				<img src="../../assets/people.png" alt="" />
				<div>系统商城</div>
			</div>
		</div>
		<div class="content">
			<div class="dynamic" @click="goFaq">
				<img class="kkdd_img" src="../../assets/tddx.png" alt="" />
				<div class="shuxian">
					<span></span>
				</div>
				<div class="kkdd_list_f">
					<div v-for="item in qaList" class="kkdd_list c_text_ellipsis_1">{{item.question}}</div>
				</div>
				<img class="kkdd_right" src="../../assets/bd_img/right.png" alt="" />
			</div>
			<template v-if="leaderList.length>0">
				<div class="leader" style="border-bottom: .2rem solid #fafafa;">
					<div class="title">
						<div class="title_label c_size_34_48">领袖风采</div>
						<div @click="lookMore('teamLeader')" class="leader_more">查看更多</div>
					</div>
					<div class="leader_list_f">
						<div class="leader_list">
							<img :src="item.avatar" @click="goLeaderDetail(item)" alt="" v-for="item in leaderList" />
						</div>
					</div>
				</div>
			</template>
			<template v-if="false">
				<div class="title">
					<div class="title_label c_size_34_48">最新发布</div>
					<div @click="lookMore('articleCompany','newest')" class="leader_more">查看更多</div>
				</div>
				<ArticleList :articleTime='false' :dataList='newArticles'></ArticleList>
			</template>
			
			<div class="title" >
				<div class="title_label c_size_34_48">推荐阅读</div>
				<div v-if="false" @click="lookMore('articleCompany','hotest')" class="leader_more">查看更多</div>
			</div>
			
			<div class="article_list_f">
				<yd-infinitescroll v-show='hotArticles.length>0' :callback="getHotArticles" ref="infinitescrollDemoArticles">
					<ArticleList :articleTime='false' slot="list" :dataList='hotArticles'></ArticleList>
					<!-- 数据全部加载完毕显示 -->
					<span slot="doneTip">没有更多数据了~~</span>
	
					<!-- 加载中提示，不指定，将显示默认加载中图标 -->
					<!--<img slot="loadingTip" src="path/img/loading.svg"/>-->
				</yd-infinitescroll>
				<NoList v-show='hotArticles.length==0'>
					<img slot='img' src="../../assets/kong_3.png" alt="" />
				</NoList>
			</div>
			
		</div>
		<!--slot='bottom'-->
		<Footer :kongFlg='true' ></Footer>
		
		
		<yd-popup v-model="showMine" position="center" width="100%" :close-on-masker='false'>
            <div class="show_mp_f" >
            	<div class="show_mp">
            		<div class="show_mp_title">温馨提示</div>
            		<div class="show_mp_label">请完善你的名片</div>
            		<div class="show_mp_btn" @click="$router.push({name:'set'})">去完善</div>
            	</div>
            </div>
        </yd-popup>
         <yd-backtop></yd-backtop>
	</yd-layout>
</template>

<script>
	//import mixinIndex from '../../mixin/mixinIndex.js'
	import Footer from '../../components/Footer/Footer.vue'
	import ArticleList from '../../components/ArticleList/ArticleList.vue'
	import { BackTop } from 'vue-ydui/dist/lib.rem/backtop';
	import { Popup } from 'vue-ydui/dist/lib.rem/popup';
	import { Swipe, SwipeItem } from 'vant';
	import { InfiniteScroll } from 'vue-ydui/dist/lib.rem/infinitescroll';
	export default {
		mixins: [],
		components: {
			[Footer.name]: Footer,
			[ArticleList.name]: ArticleList,
			[BackTop.name]: BackTop,
			[Popup.name]: Popup,
			[Swipe.name]: Swipe,
			[SwipeItem.name]: SwipeItem,
			[InfiniteScroll.name]: InfiniteScroll,

		},
		data() {
			return {
				showMine:false,
				liveList: [],
				pageNum: 1,
				pageCount: 10,
				showPop: false,
				teacherList: [], //讲师团队列表
				passwordNum: '',
				listObj: {},
				mineObj: {},
				
				bannerList: [],//轮播
				newArticles:[],//最新文章
				hotArticles:[],//最热文章
				teamArticles:[],//团队动向
				leaderList:[],//领袖风采
				qaList:[],//c常见问题
				unreadTotal:0,
				pageNumHot:1,
			}
		},
		created() {
			
			
			if((!this.$route.query.str) && this.$root.config.oldUrlStr) {
				let urlName = 'index'
				if(this.$root.config.oldUrlStr) {
					urlName = this.$root.config.oldUrlStr != 'login' ? this.$root.config.oldUrlStr : 'index'
				}
				let query = {},
					countNum = 1;
				//对参数进行整理
				if(this.$root.config.keyNum && this.$root.config.keyNum >= 1) {
					for(let key in this.$root.config) {
						if(key == ('paramsVal' + countNum)) {
							query[this.$root.config['paramsKey' + countNum]] = this.$root.config['paramsVal' + countNum]
							if(countNum == this.$root.config.keyNum) {
								break
							}
							countNum++
						}
					}
				}
				this.$router.push({
					name: urlName,
					query: query
				})
			}
		},
		watch: {

		},
		computed: {

		},
		async mounted() {
			document.title = '首页'
			var ua = navigator.userAgent;
			if(this.$root.isPc != 'pc' && ua.match(/MicroMessenger/i) != 'MicroMessenger' && (this.$root.isPcOS == 'Phone' || this.$root.isPcOS == 'Linux')) {
				await this.getToken()
			}
			console.log(this.$root.userInfo)
			this.getIndex();
			this.getMine();
			
			this.getHotArticles();//最热文章
			//this.livingList()
		},
		methods: {
			//获取名片信息
			getMine(){
				this.$root.ajax({
					name: 'my/namecard',
					params: {
						uid:this.$root.userInfo.me.id
					}
				}).then((d) => {
					if(!d.data.wechat_code){
						this.showMine = false
					}
				})
			},
			goSearch(){
				this.$router.push({name:'search'})
			},
			goBannerView(item){
				if(item.kind ===1||item.kind ===3){
					//聚焦公司
					this.$router.push({name:'articleDetail',query:{id:item.oid}})
				}
				else if(item.kind ===20){
					//商品ID
					this.$router.push({name:'productDetail',query:{id:item.oid}})
				}
				else if(item.kind ===5){
					//团队动向
					this.$router.push({name:'teamTrendDetail',query:{id:item.oid}})
				}else if(item.kind ===4){
					//领袖详情
					this.$router.push({name:'leaderDetail',query:{id:item.oid,kind:1}})
				}
			},
			lookMore(str,portStr) {
				this.$router.push({
					name:str,
					query:{
						port:portStr
					}
				})
			},
			goFaq() {
				this.$router.push({
					name:'faq',
					query:{
						cate_id:5
					}
				})
			},
			//输入密码
			postPassword() {
				if(this.passwordNum.length == 6) {
					if(this.passwordNum == this.listObj.password) {
						if(this.listObj.kind === 0) {
							this.$router.push({
								name: 'liveRoom',
								query: {
									id: this.listObj.id,
									password: this.listObj.password
								}
							})
						} else {
							this.$router.push({
								name: 'live',
								query: {
									id: item.id,
									kind: this.listObj.kind,
								}
							})
						}
					} else {
						this.$dialog.toast({
							mes: '请输入正确的六位密码',
							timeout: 1500
						});
					}
				} else {
					this.$dialog.toast({
						mes: '请根据提示正确输入',
						timeout: 1500
					});
				}
			},
			//获取列表
			livingList() {
				this.$root.ajax({
					name: 'Live/livingList',
					params: {
						page: this.pageNum,
						count: this.pageCount,
					}
				}).then((d) => {
					for(let a = 0; a < d.data.live_list.length; a++) {
						d.data.live_list[a].time = this.$root.getDate(new Date(d.data.live_list[a].begin_time * 1000))
					}
					this.liveList = [...this.liveList, ...d.data.live_list];

					if(this.liveList.length >= d.data.live_total) {
						/* 所有数据加载完毕 */
						this.$refs.infinitescrollDemo.$emit('ydui.infinitescroll.loadedDone');
						return;
					}

					/* 单次请求数据完毕 */
					this.$refs.infinitescrollDemo.$emit('ydui.infinitescroll.finishLoad');

					this.pageNum++;
				})
			},
			//安卓，苹果端登录
			getToken() {
				return new Promise((resolve, reject) => {
					let params = {};
					if(this.$root.isPc() == 'android') {
						params = {
							uid: this.$root.config.androidOrIosObj.user_uid,
							nick_name: this.$root.config.androidOrIosObj.user_name,
							avatar: this.$root.config.androidOrIosObj.user_photo,
							client: 1, //1安卓，2ios。3web
							item: 2, //1、报名通道；2、直销万事通APP
							channel: this.$root.config.channel,
							mobile: '',
						}
					} else {
						params = {
							uid: this.$root.config.androidOrIosObj.user_uid,
							nick_name: this.$root.config.androidOrIosObj.user_name,
							avatar: this.$root.config.androidOrIosObj.user_photo,
							client: 2, //1安卓，2ios。3web
							item: 2, //1、报名通道；2、直销万事通APP
							channel: this.$root.config.channel,
							mobile: '',
						}
					}
					this.$root.ajax({
						name: 'Index/loginin',
						params: params
					}).then((d) => {
						this.$root.userInfo = d.data
						sessionStorage.setItem('wst_lvzy_userInfo', JSON.stringify(d.data));
						resolve()
					})
				})
			},
			//去下一个页面，直播，回放，预播
			goNext(item) {
				//清空密码
				this.listObj = {};

				if(item.kind === 0) {
					//判断是否需要密码
					//非（视频需要会员，且已经开通会员）
					if(item.member == 1) {
						if(this.mineObj.member_status != 1) {
							//弹出开通会员框
							this.$dialog.confirm({
								title: '温馨提示',
								mes: '该场直播需要开通会员权限才能观看',
								opts: [{
										txt: '取消',
										color: '#999999',
										callback: () => {

										},
									},
									{
										txt: '开通会员',
										color: '#35BF7E',
										callback: () => {
											this.$router.push({
												name: 'vipOpen'
											})
										}
									},
								]
							});
							return
						}
					}
					//判断是否需要密码
					if(item.bpass == 1) {
						//弹出密码框
						this.showPop = true;
						this.listObj = Object.assign({}, this.listObj, item)
						this.passwordNum = ''
						return
					}
					this.$router.push({
						name: 'liveRoom',
						query: {
							id: item.id,
						}
					})
				} else {
					this.$router.push({
						name: 'live',
						query: {
							id: item.id,
							kind: item.kind,
						}
					})
				}

			},
			getIndex() {
				this.$root.ajax({
					name: 'index',
					params: {},
					type:'get'
				}).then((d) => {
					for(let a = 0 ;a<d.data.new_articles.length;a++){
						d.data.new_articles[a].newTime=this.$root.getDate(new Date(d.data.new_articles[a].create_time*1000))
					}
					for(let a = 0 ;a<d.data.hot_articles.length;a++){
						d.data.hot_articles[a].newTime=this.$root.getDate(new Date(d.data.hot_articles[a].create_time*1000))
					}
					this.unreadTotal = d.data.unread_total
					this.bannerList = d.data.banner_list//轮播
					this.newArticles = d.data.new_articles//最新文章
					//this.hotArticles = d.data.hot_articles//最热文章
					this.teamArticles = d.data.team_articles//团队动向
					this.leaderList = d.data.leader_list//领袖风采
					this.qaList = d.data.qa_list//常见问题
					
				})
			},
			getHotArticles(){
				this.$root.ajax({
					name: 'article/hotest',
					params: {
						page:this.pageNumHot,
						count:20,
					},
				}).then((d) => {
					
					for(let a = 0; a < d.data.article_list.length; a++) {
						d.data.article_list[a].newTime = this.$root.getDate(new Date(d.data.article_list[a].create_time * 1000))
					}
					this.hotArticles = [...this.hotArticles, ...d.data.article_list];
					if(this.hotArticles.length >= d.data.article_total) {
						/* 所有数据加载完毕 */
						this.$refs.infinitescrollDemoArticles.$emit('ydui.infinitescroll.loadedDone');
						return;
					}

					/* 单次请求数据完毕 */
					this.$refs.infinitescrollDemoArticles.$emit('ydui.infinitescroll.finishLoad');

					this.pageNumHot++;
				})
			},
			goNextPage(str,cate_id){
				console.log(str)
				this.$router.push({
					name:str,
					query:{
						cate_id:cate_id
					}
				})
			},
			goLeaderDetail(item){
				this.$router.push({
					name:'leaderDetail',
					query:{
						id:item.id
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	@import './index.scss';
	#NoList{
		.span{
			padding-bottom:1rem;
		}
	}
</style>